//package com.example.demolearn.aspect;
//
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
//import org.springframework.core.annotation.AnnotationUtils;
//import org.springframework.web.bind.annotation.RequestBody;
//
//import java.lang.reflect.Method;
//import java.lang.reflect.Parameter;
//import java.util.Arrays;
//import java.util.Optional;
//
//@Aspect
//@Slf4j
//public class HttpLogHandler {
//
//    @Pointcut("@annotation(com.example.demolearn.aspect.HttpLog)")
//    public void logAnnotation(JoinPoint joinPoint) {
//        getLogAnnotation(joinPoint);
//        getRequestBodyParam(joinPoint);
//    }
//
//    private Optional<HttpLog> getLogAnnotation(JoinPoint joinPoint) {
//        if (joinPoint instanceof MethodInvocationProceedingJoinPoint) {
//            Signature signature = joinPoint.getSignature();
//            if (signature instanceof MethodSignature) {
//                MethodSignature methodSignature = (MethodSignature) signature;
//                Method method = methodSignature.getMethod();
//                if (method.isAnnotationPresent(HttpLog.class)) {
//                    return Optional.of(method.getAnnotation(HttpLog.class));
//                }
//            }
//        }
//        return Optional.empty();
//    }
//    private Optional<Object> getRequestBodyParam(JoinPoint joinPoint){
//        if (joinPoint instanceof MethodInvocationProceedingJoinPoint) {
//            Signature signature = joinPoint.getSignature();
//            if (signature instanceof MethodSignature) {
//                MethodSignature methodSignature = (MethodSignature) signature;
//                Method method = methodSignature.getMethod();
//                Parameter[] methodParameters = method.getParameters();
//                if (null != methodParameters
//                        && Arrays.stream(methodParameters).anyMatch(p-> AnnotationUtils.findAnnotation(p, RequestBody.class) != null)) {
//                    return Optional.of(joinPoint.getArgs());
//                }
//            }
//        }
//        return Optional.empty();
//    }
//
//
//
//
//}
//
